package com.atguigu.day20.syn01.s3;

//todo 张三线程
public class ZsThread extends Thread {
    private Account account;
    public ZsThread(Account account) {
        this.account = account;
    }
    @Override
    public void run() {

       // synchronized (account) {
        synchronized ("ABC") {
            //1.校验余额
            if (account.money >= 1500) {

                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                //2.满足 取钱
                account.withDraw(1500);
                System.out.println(this.getName() + "取钱成功,余额是" + account.money + "元");
            } else {
                //3.不满足 提示信息 余额不足
                System.out.println(this.getName() + "取钱失败 余额不足,余额是" + account.money + "元");
            }
        }
    }
}
